<?php
/**
 * Created by PhpStorm.
 * User: liuyu
 * Date: 2018/11/19
 * Time: 11:19
 */

namespace app\api\controller\v5;


use app\api\controller\v2\Auth;
use app\common\model\Informant;
use app\common\model\MiddleInformant;

/**评论举报相关接口
 * Class ComplaintComment
 * @package app\api\controller\v5
 */
class ComplaintComment extends Auth
{

    public function index()
    {
        if (!request()->isPost())
        {
            return show(config('code.error'), '未知操作', [], 403);
        }

        $comment_id = input('param.comment_id/d');
        $content = input('param.content/s');

        $arr = [
            1 => '垃圾营销',
            2 => '涉黄信息',
            3 => '有害信息',
            4 => '违法信息',
            5 => '侵害人身权益',
            6 => '其他原因'
        ];

        $offset = array_search($content, $arr) ?? 0;

        $arr = [
            'comment_id' => $comment_id,
            'info_id' => $offset,
            'uid' => $this->user['id'],
            'type' => 1
        ];

        $res = (new MiddleInformant())->SaveData($arr);
        if ($res === false)
        {
            return show(config('code.error'), '举报失败');
        }
        return show(config('code.success'), '举报成功');
    }
}
